package com.apex.shared.knife4j.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
 * Knife4j配置
 *
 * @author MoNaiHui
 */
@AutoConfiguration
@ConditionalOnProperty(prefix = "knife4j", name = "enable", havingValue = "true", matchIfMissing = true)
public class Knife4jConfig {

    @Value("${spring.application.version}")
    private String API_INFO_VERSION;

    private static final String API_INFO_TITLE = "ApexX-Cloud 微服务聚合Api接口文档";
    private static final String API_INFO_DESCRIPTION = "ApexX-Cloud 微服务聚合Api";
    private static final String Terms_Of_Service = "ApexX-Cloud 是一个开源项目，遵循 Apache 2.0 许可证。用户可以自由使用、复制、修改、合并、发布、分发和销售该软件的副本，但需要保留原始作者的署名和相关许可证信息。该软件按“原样”提供，不提供任何明示或暗示的保证。使用者需遵守 Apache 2.0 许可证中的条款和条件。";
    private static final String CONTACT_NAME = "ApexX-Cloud";
    private static final String CONTACT_EMAIL = "1182002995@qq.com";
    private static final String CONTACT_URL = "https://gitee.com/DMRilakkuma/ApexX-Cloud";


    /**
     * @return Knife4j openAPI配置
     */
    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title(API_INFO_TITLE)
                        .description(API_INFO_DESCRIPTION)
                        .version(API_INFO_VERSION)
                        .termsOfService(Terms_Of_Service)
                        .contact(new Contact().name(CONTACT_NAME)
                                .email(CONTACT_EMAIL)
                                .url(CONTACT_URL))
                );
    }

}